package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class ChannelController {

    @Autowired
    private IWmChannelService iWmChannelService;

    /**
     * 查询频道列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "查询频道列表",notes = "author:mcm")
    @ApiImplicitParam(name = "dto",value = "查询对象",required = true,dataType = "ChannelDto")
    public ResponseResult listByPage(@RequestBody ChannelDto dto) {
        return iWmChannelService.listByPage(dto);
    }

    /**
     * 添加频道
     * @param wmChannel
     * @return
     */
    @PostMapping
    @ApiOperation(value = "添加频道",notes = "author:mcm")
    @ApiImplicitParam(name = "wmChannel",value = "添加对象",required = true,dataType = "WmChannel")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel){
        return iWmChannelService.saveChannel(wmChannel);
    }

    /**
     * 修改频道
     * @param wmChannel
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改频道",notes = "author:mcm")
    @ApiImplicitParam(name = "wmChannel",value = "修改对象",required = true,dataType = "WmChannel")
    public ResponseResult updateById(@RequestBody WmChannel wmChannel){
        return iWmChannelService.updateChannel(wmChannel);
    }

    /**
     * 根据id删除频道
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除频道",notes = "author:mcm")
    @ApiImplicitParam(name = "id",value = "请求id",required = true,dataType = "Integer")
    public ResponseResult deleteById(@PathVariable Integer id){
        return iWmChannelService.deleteChannel(id);
    }

    /**
     * 查询所有频道
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult channels(){
        List<WmChannel> list = iWmChannelService.list();
        return ResponseResult.okResult(list);
    }
}
